// react包的打包配置
import {getPackageJSON, resolvePkgPath, getBaseRollupPlugins} from './utils';
import generatePackageJson from 'rollup-plugin-generate-package-json';

const {name, module} = getPackageJSON('react');

// react包路径
const pkgPath = resolvePkgPath(name);
// react包产物路径
const pkgDistPath = resolvePkgPath(name, true);

export default [
  // react包
  {
    input: `${pkgPath}/${module}`, // 打包入口地址
    output: {
      file: `${pkgDistPath}/index.js`,
      name: 'React',
      format: 'umd', // 打包类型，umd格式
    },
    plugins: [
      ...getBaseRollupPlugins(),
      generatePackageJson({
        inputFolder: pkgPath,
        outputFolder: pkgDistPath,
        // 定义打包后的package.json中的内容
        baseContents: ({name, description, version}) => ({
          name,
          description,
          version,
          main: 'index.js',
        }),
      }),
    ],
  },
  // jsx-runtime包
  {
    input: `${pkgPath}/src/jsx.ts`, // 打包入口地址
    output: [
      // jsx-runtime
      {
        file: `${pkgDistPath}/jsx-runtime.js`,
        name: 'jsx-runtime',
        format: 'umd', // 打包类型，umd格式
      },
      // jsx-dev-runtime
      {
        file: `${pkgDistPath}/jsx-dev-runtime.js`,
        name: 'jsx-dev-runtime',
        format: 'umd', // 打包类型，umd格式
      },
    ],
    plugins: getBaseRollupPlugins(),
  },
];
